package edu.gatech.wms.junits;

import java.util.LinkedList;

import android.test.AndroidTestCase;
import edu.gatech.wms.controllers.UserManager;
import edu.gatech.wms.models.User;

/*
 * @author Sagar Gupta
 * This class test the create user functionality of the app.
 */
public class SagarJUnit extends AndroidTestCase
{
	private static final int userOneID  = 876787612, userTwoID = 123418716;
	private static LinkedList<Integer> allUsers;
	
	/*
	 * This method adds a user and checks to see if the user is properly inserted in the database.
	 */
	public void test1OneTimeSetup()
	{
		int one = UserManager.dbMain.add(new User("Sagar", "Gupta", userOneID, "password", "sagar@gupta.com", true));
		int two = UserManager.dbMain.add(new User("Gino", "McArtsy", userTwoID, "P@zzw3rd", "gino@mccarty.com", false));
		allUsers = (LinkedList<Integer>) UserManager.getAllUsers();
		assertEquals(userOneID, one);
		assertEquals(userTwoID, two);
	}
	
	/*
	 *  This method adds a user and checks to see if the user can be properly accessed from the database.
	 */
	public void test2IfUsersExist()
	{
		int one = 0, two = 0;
		for(int id : allUsers)
		{
			if(UserManager.getUserContact(id).equals("sagar@gupta.com"))
			{
				one = id;
			}
			else if(UserManager.getUserContact(id).equals("gino@mccarty.com"))
			{
				two = id;
			}
		}
		
		assertEquals(userOneID, one);
		assertEquals(userTwoID, two);
	}
	
	/*
	 *  This method checks to see if the added user's name is correct.
	 */
	public void test3Name()
	{
		assertEquals(UserManager.getUserFullName(userOneID), "Sagar Gupta");
		assertEquals(UserManager.getUserFullName(userTwoID), "Gino McArtsy");
	}
	
	/*
	 *  This method checks to see of the added user's email is correct.
	 */
	public void test4Email()
	{
		assertEquals(UserManager.getUserContact(userOneID), "sagar@gupta.com");
		assertEquals(UserManager.getUserContact(userTwoID), "gino@mccarty.com");
	}
	
	/*
	 *  This method checks that the password id the same as the added user.
	 */
	public void test5Password()
	{
		assertEquals(UserManager.dbMain.queryUser(userOneID).getPassword(), "password");
		assertEquals(UserManager.dbMain.queryUser(userTwoID).getPassword(), "P@zzw3rd");
	}
	
	/*
	 *  This method checks that the admin value is the same as the added user.
	 */
	public void test6Admin()
	{
		assertEquals(UserManager.getAdmin(userOneID), true);
		assertEquals(UserManager.getAdmin(userTwoID), false);
	}

}
